/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package coba.service.impl;

import java.util.List;

import com.liferay.portal.kernel.exception.SystemException;

import coba.NoSuchFormularioGrupoException;
import coba.model.FormularioGrupo;
import coba.model.Guia;
import coba.service.FormularioGrupoLocalServiceUtil;
import coba.service.RecorridoSolicitudLocalServiceUtil;
import coba.service.base.FormularioGrupoLocalServiceBaseImpl;
import coba.service.persistence.FormularioGrupoUtil;

/**
 * The implementation of the FormularioGrupo local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link coba.service.FormularioGrupoLocalService} interface.
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author rodri042
 * @see coba.service.base.FormularioGrupoLocalServiceBaseImpl
 * @see coba.service.FormularioGrupoLocalServiceUtil
 */
public class FormularioGrupoLocalServiceImpl
	extends FormularioGrupoLocalServiceBaseImpl {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never reference this interface directly. Always use {@link coba.service.FormularioGrupoLocalServiceUtil} to access the FormularioGrupo local service.
	 */
	
	public FormularioGrupo add(long solicitudId) throws SystemException {

		FormularioGrupo formularioGrupo = formularioGrupoPersistence.
				create(counterLocalService.increment(FormularioGrupo.class.getName()));

		formularioGrupo.setSolicitudId(solicitudId);
		formularioGrupo.setCodigoUnico(java.util.UUID.randomUUID().toString());
		
		return super.addFormularioGrupo(formularioGrupo);

	}
	
	public FormularioGrupo getBySolicitudId(long solicitudId) throws SystemException {
		List<FormularioGrupo> listFormularioGrupo = this.formularioGrupoPersistence.findBySolicitudId(solicitudId);
		
		if (listFormularioGrupo != null && !listFormularioGrupo.isEmpty())
			return listFormularioGrupo.get(0);
		else
			return null;
	}
	
	public FormularioGrupo getByCodigoUnico(String codigoUnico) throws SystemException {
		List<FormularioGrupo> listFormularioGrupo = this.formularioGrupoPersistence.findByCodigoUnico(codigoUnico);
		
		if (listFormularioGrupo != null && !listFormularioGrupo.isEmpty())
			return listFormularioGrupo.get(0);
		else
			return null;
	}
}